﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;

public partial class News_PassedList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gridbind();
            ddlbind();
            SetDatePicker();
        }
    }

    //设置日期选择框的属性
    protected void SetDatePicker()
    {
        txtTime1.Attributes.Add("onfocus", "WdatePicker({maxDate:'#F{$dp.$D(\\'" + txtTime2.ClientID + "\\')||\\'2120-10-01\\'}'})");
        txtTime2.Attributes.Add("onfocus", "WdatePicker({minDate:'#F{$dp.$D(\\'" + txtTime1.ClientID + "\\')}',maxDate:'2120-10-01'})");

    }


    //ddl绑定
    protected void ddlbind()
    {
        StringBuilder sqlstr1 = new StringBuilder("select btnname from Sys_Guide order by id");
        StringBuilder sqlstr2 = new StringBuilder("select collegename from Dict_College order by collegeid");
        PM.Code.Web.controlbind.BindDropDownList(ddlType, sqlstr1.ToString(), "btnname", "btnname");
        PM.Code.Web.controlbind.BindDropDownList(ddlPdepart, sqlstr2.ToString(), "collegename", "collegename");
        PM.Code.Web.controlbind.BindDropDownList(ddlDepart, sqlstr2.ToString(), "collegename", "collegename");
    }
    protected void gridbind()
    {
        StringBuilder sqlstrfield = new StringBuilder();
        StringBuilder sqlstrwhere = new StringBuilder();
        getField(ref sqlstrfield);
        getWhere(ref sqlstrwhere);
        PM.Code.Web.controlbind.BindGridViewPublicProc(GridView1, AspNetPager1, "View_Projects", "id", sqlstrfield.ToString(), "type asc,builddate desc", sqlstrwhere.ToString(), true);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        gridbind();
    }
    //设置查询字段
    protected void getField(ref StringBuilder sqlstrfield)
    {
        sqlstrfield.Append("type,pname,plevel,pcollege,name,depart,approvaldate");
    }
    //设置查询条件
    protected void getWhere(ref StringBuilder sqlstrwhere)
    {
        sqlstrwhere.Append(" 1=1 ");
        if (txtPname.Text.Trim()!="")
        {
            sqlstrwhere.AppendFormat("and pname like '%{0}%' ", txtPname.Text.Trim());
        }
        if (ddlType.SelectedValue!="")
        {
            sqlstrwhere.AppendFormat("and type='{0}' ", ddlType.SelectedValue.ToString());
        }
        if (ddlLevel.SelectedValue!="")
        {
            sqlstrwhere.AppendFormat("and plevel='{0}' ", ddlLevel.SelectedValue.ToString());
        }
        if (txtTime1.Value.Trim()!=""&&txtTime2.Value.Trim()!="")
        {
            sqlstrwhere.AppendFormat("and approvaldate between '{0}' and '{1}' ", txtTime1.Value.Trim(), txtTime2.Value.Trim());
        }
        if (txtName.Text.Trim()!="")
        {
            sqlstrwhere.AppendFormat("and name='{0}' ", txtName.Text.Trim());
        }
        if (ddlDepart.SelectedValue!="")
        {
            sqlstrwhere.AppendFormat("and depart='{0}' ", ddlDepart.SelectedValue.ToString());
        }
        if (ddlPdepart.SelectedValue!="")
        {
            sqlstrwhere.AppendFormat("and pcollege='{0}' ", ddlPdepart.SelectedValue.ToString());
        }
        sqlstrwhere.Append("and status in (3,4,11) ");
    }
    //过长的字符截断
    static public string strTrim(string str)
    {
        return PM.Code.Basic.pmbasic.strCal(str, 40);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex == -1)
        return;
        string strAllContent = ((Label)e.Row.Cells[1].FindControl("lblhidden")).Text.Trim();
        e.Row.Cells[1].Attributes.Add("title", strAllContent);
    }
    protected void btnSeach_Click(object sender, ImageClickEventArgs e)
    {
        gridbind();
    }
}
